#ifndef __RegClient__
#define __RegClient__

#include "RegisterNotification.h"
#include "Poco/Runnable.h"
#include <iostream>
#include <vector>
#include "IRegClient.h"
#include "Client.h"
#include "Poco/Thread.h"



using namespace std;
using Poco::Thread;

class RegClient : public Poco::Runnable, IRegClient
{
public:
    static bool  CreateInstance(IRegClient*& pRegClient);
    virtual int  Register(PBasicInformation pInfo);
    virtual int  Login(PBasicInformation pInfo);
    virtual void Logoff();
    virtual int  ChangePassword(const string new_password);
    virtual int  UnBind(PBasicInformation pInfo);
    virtual int  GetKeyInfo(PKeyInfo);
    virtual bool Initialize(const string server_ip, unsigned short port);
    virtual void Unintialize();
    virtual bool Test();
    virtual const string ErrorCodeToString(int nError);
public:
    // IRegisterNotification
    bool RegisterNotification(IRegisterNotification* pClient);
    bool UnRegisterNotification(IRegisterNotification* pClient);

public:
    // runnable
    bool IsRegistered(const string hwid);
    void run();

private:
    RegClient():m_stop(false),m_heartbeat_fail_count(0){}
    ~RegClient(){m_stop = true;}
    int HeartBeat();
    static RegClient* s_pRegClient;
    vector<IRegisterNotification*> s_vNotificationClient;
    string server_ip;
    unsigned short server_port;
    Client m_client;
    bool m_stop;
    Thread m_thread;
    int m_heartbeat_fail_count;

};

#endif